﻿using System.Drawing;
using H2.NET.Business;
using H2.NET.Common;
using H2.NET.Data.Common;
using H2.NET.Web.Pages.SMD.Model;
using H2.NET.Web.Pages.SMD.Service;
using H2.NET.Web.Workflow.DwzCode;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;

namespace H2.NET.Web.Pages.SMD.AjaxTools
{
    public partial class AjaxUpload : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            #region 删除附件
            if (AksRequest.GetQueryString("action") == "delete")
            {
                string id = AksRequest.GetFormString("id");
                string stat = "";
                if (!string.IsNullOrEmpty(id))
                {
                    (H2.NET.Business.t_Attachment.id == id).Edit<H2.NET.Business.t_Attachment>(Storage.Context1, o =>
                    {
                        o.Time = System.DateTime.Now;
                        o.Status = 2;
                    });
                    stat = "success";
                }
                string res = "{ stat:'" + stat + "'}";
                SuccessMsg(stat);
                return;
            }
            #endregion
            #region 下载附件
            else if (AksRequest.GetQueryString("action") == "download")
            {
                string id = AksRequest.GetQueryString("id");
                H2.NET.Business.t_Attachment attachment = (H2.NET.Business.t_Attachment.id == id).ListFirst<H2.NET.Business.t_Attachment>();
                if (attachment != null && (attachment.FilePath == null || !File.Exists(attachment.FilePath)))
                {
                    SuccessMsg("对不起，该文件不存在！");
                    return;
                }
                //以字符流的形式下载文件
                FileStream fs = new FileStream(attachment.FilePath, FileMode.Open);
                byte[] bytes = new byte[(int)fs.Length];
                fs.Read(bytes, 0, bytes.Length);
                fs.Close();
                Response.ContentType = "application/octet-stream";
                //通知浏览器下载文件而不是打开
                Response.AddHeader("Content-Disposition", "attachment;  filename=" + HttpUtility.UrlEncode(attachment.FileName, System.Text.Encoding.UTF8));
                Response.BinaryWrite(bytes);
                Response.Flush();
                Response.End();
            }
            #endregion
            #region 上传批量保证金返还
            else if (AksRequest.GetQueryString("action") == "change" &&
                Path.GetFileName(Request.Files[0].FileName).Split('.')[0] == "保证金清单")
            {
                var files = Request.Files; //这里只能用<input type="file" />才能有效果,因为服务器控件是HttpInputFile类型
                var msg = string.Empty;
                var error = string.Empty;
                var res = "";
                var moreTwo = false;
                var bs = Util.AppSettings("path");
                var path = bs + @"\" + files[0].FileName;
                var stat = true;
                if (files.Count > 0)
                {
                    var taskid = AksRequest.GetQueryString("taskid");
                    var PProcess = AksRequest.GetQueryString("PProcess");
                    var PStep = AksRequest.GetQueryString("PStep");
                    var PIncident = AksRequest.GetQueryInt("PIncident");
                    var FileClass = AksRequest.GetQueryString("FileClass");
                    var taskAPI = new TaskAPI(taskid);
                    var date = System.DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    var fileName = Path.GetFileName(files[0].FileName);
                    if (!string.IsNullOrEmpty(fileName))
                    {
                        var vdepostiBacth = (v_DepositBatchChange._AuthID != "").List<v_DepositBatchChange>();
                        var type = Path.GetExtension(fileName);
                        if (type == ".xls" || type == ".xlsx")
                        {
                            #region 上传清单

                            if (fileName.Split('.')[0] == "保证金清单")
                            {
                                Logging.GetLogger().Info("保证金清单读取");
                                IWorkbook hssfworkbook;
                                files[0].SaveAs(bs + @"\change" + type);
                                using (var fl = new FileStream(bs + @"\change" + type, FileMode.Open, FileAccess.Read))
                                {
                                    hssfworkbook = WorkbookFactory.Create(fl);
                                }
                                var sheet = hssfworkbook.GetSheetAt(0);
                                var rows = sheet.GetRowEnumerator();
                                bool iswrong = false;
                                var errorString = "<table class='formTable'>" +
                                                  "<tr>" +
                                                  "<td>序号</td><td>授权号</td><td>区域</td><td>省份</td><td>城市</td><td>城市类型</td><td>客户SAP账号</td><td>客户名称</td>" +
                                                  "<td>店面名称</td><td>渠道类型</td><td>设备安装时间</td><td>规定资产编号</td><td>发放前保证金余额</td><td>发放金额</td>" +
                                                  "<td>发放后金额</td><td>是否发放</td>" +
                                                  "</tr>";
                                Logging.GetLogger().Info("开始准备");
                                while (rows.MoveNext())
                                {
                                    bool isRong = false;
                                    var errorStr = "";
                                    var row = (IRow)rows.Current;
                                    var index = row.RowNum;
                                    if (index == 0)
                                    {
                                        continue;
                                    }
                                    var authid = Value(row.GetCell(0));
                                    var region = Value(row.GetCell(1));
                                    var province = Value(row.GetCell(2));
                                    var city = Value(row.GetCell(3));
                                    var cityclass = Value(row.GetCell(4));
                                    var dealerCode = Value(row.GetCell(5));
                                    var dealername = Value(row.GetCell(6));
                                    var storename = Value(row.GetCell(7));
                                    var channel = Value(row.GetCell(8));
                                    var deviceInstallDate = row.GetCell(9).DateCellValue;
                                    var fullsetsn = Value(row.GetCell(10));
                                    var amount = Value(row.GetCell(11));
                                    var returnAmount = Value(row.GetCell(12));
                                    var nowAmount = Value(row.GetCell(13));
                                    var needFF = Value(row.GetCell(14));
                                    //Logging.GetLogger().Info("ceshi");
                                    var deposit =
                                        vdepostiBacth.FirstOrDefault(t => t.AuthID == authid & t.FullSetSN.Contains(fullsetsn));
                                    //Logging.GetLogger().Info("ceshi2" + deposit.ToString() + fullsetsn);
                                    if (deposit == null)
                                    {
                                        isRong = true;
                                        errorStr += "<tr><td>" + (index + 1) + "</td><td><font style='color:red'>" + authid +
                                                    "</font></td><td><font>" + region + "</font></td>";
                                    }
                                    //else if (region.Trim().ToLower() != deposit.Region.Trim().ToLower())
                                    //{
                                    //    isRong = true;
                                    //    errorStr += "<tr><td>" + (index + 1) + "</td><td>" + authid +
                                    //                "</td><td><font style='color:red'>" + region + "</font></td>";
                                    //}
                                    else
                                    {
                                        errorStr += "<tr><td>" + (index + 1) + "</td><td>" + authid + "</td><td><font>" +
                                                    region + "</font></td>";
                                    }

                                    //if (deposit != null && province.Trim() != deposit.Province.Trim())
                                    //{
                                    //    isRong = true;
                                    //    errorStr += "<td><font style='color:red'>" + province + "</font></td>";
                                    //}
                                    //else
                                    //{
                                    errorStr += "<td><font>" + province + "</font></td>";
                                    //}

                                    //if (deposit != null && city.Trim() != deposit.CityName.Trim())
                                    //{
                                    //    isRong = true;
                                    //    errorStr += "<td><font style='color:red'>" + city + "</font></td>";
                                    //}
                                    //else
                                    //{
                                    errorStr += "<td><font>" + city + "</font></td>";
                                    //}
                                    //if (deposit != null && deposit.CityClass != null && cityclass.Trim() != deposit.CityClass.Trim())
                                    //{
                                    //    isRong = true;
                                    //    errorStr += "<td><font style='color:red'>" + cityclass + "</font></td>";
                                    //}
                                    //else
                                    //{
                                    errorStr += "<td><font>" + cityclass + "</font></td>";
                                    //}
                                    if (deposit != null && dealerCode.Trim() != deposit.DealerCode.Trim())
                                    {
                                        isRong = true;
                                        errorStr += "<td><font style='color:red'>" + dealerCode + "</font></td>";
                                    }
                                    else
                                    {
                                        errorStr += "<td><font>" + dealerCode + "</font></td>";
                                    }

                                    //if (deposit != null && dealername.Trim() != deposit.Name.Trim())
                                    //{
                                    //    isRong = true;
                                    //    errorStr += "<td><font style='color:red'>" + dealername + "</font></td>";
                                    //}
                                    //else
                                    //{
                                    errorStr += "<td><font>" + dealername + "</font></td>";
                                    //}

                                    //if (deposit != null && storename.Trim() != deposit.StoreName.Trim())
                                    //{
                                    //    isRong = true;
                                    //    errorStr += "<td><font style='color:red'>" + storename + "</font></td>";
                                    //}
                                    //else
                                    //{
                                    errorStr += "<td><font>" + storename + "</font></td>";
                                    //}
                                    //if (deposit != null && channel.Trim() != (deposit.Channel.Trim()))
                                    //{
                                    //    isRong = true;
                                    //    errorStr += "<td><font style='color:red'>" + channel + "</font></td>";
                                    //}
                                    //else
                                    //{
                                    errorStr += "<td><font>" + channel + "</font></td>";
                                    //}
                                    if (deposit != null && deviceInstallDate.Year == 1)
                                    {
                                        isRong = true;
                                        errorStr += "<td><font style='color:red'>空</font></td><td>" + fullsetsn + "</td>";
                                    }
                                    else if (deposit == null)
                                    {
                                        errorStr += "<td><font>" + deviceInstallDate + "</font><td><font style='color:red'>" + fullsetsn +
                                                    "</font></td></td>";
                                    }
                                    else
                                    {
                                        errorStr += "<td><font>" + deviceInstallDate + "</font><td>" + fullsetsn +
                                                    "</td></td>";
                                    }
                                    if (deposit != null && Utils.StrToInt(amount, 0) != deposit.Amount)
                                    {
                                        isRong = true;
                                        errorStr += "<td><font style='color:red'>" + amount + "</font></td>";
                                    }
                                    else
                                    {
                                        errorStr += "<td><font>" + amount + "</font></td>";
                                    }
                                    if (deposit != null && Utils.StrToInt(amount, 0) < Utils.StrToInt(returnAmount, 0))
                                    {
                                        isRong = true;
                                        errorStr += "<td><font style='color:red'>" + returnAmount + "</font></td>";
                                    }
                                    else
                                    {
                                        errorStr += "<td><font>" + returnAmount + "</font></td>";
                                    }
                                    if (Utils.StrToInt(nowAmount, 0) < 0)
                                    {
                                        isRong = true;
                                        errorStr += "<td><font style='color:red'>" + nowAmount + "</font></td>";
                                    }
                                    else
                                    {
                                        errorStr += "<td><font>" + nowAmount + "</font></td>";
                                    }
                                    if (Utils.StrToInt(returnAmount, 0) == 0 && needFF.Trim() == "是")
                                    {
                                        isRong = true;
                                        errorStr += "<td><font style='color:red'>" + needFF + "</font></td>";
                                    }
                                    else
                                    {
                                        errorStr += "<td><font>" + needFF + "</font></td>";
                                    }
                                    if (isRong)
                                    {
                                        iswrong = true;
                                        errorString += errorStr + "</tr>";
                                    }

                                }

                                if (iswrong)
                                {
                                    errorString += "</table>";
                                    res = "{error:'数据错误！',info:'" + errorString.Replace("'", "\"") + "'}";
                                    Response.ContentType = "text/html";
                                    Response.Write(res);
                                    Response.End();
                                    return;
                                }
                            }


                            #endregion


                        }
                        else
                        {
                            res = "{error:'请上传exel格式的文件！'}";
                            Response.Write(res);
                            Response.End();
                        }
                    }
                    (t_Attachment.fileName == files[0].FileName
                        & t_Attachment.incident == TaskAPI.Incident
                        & t_Attachment.process == TaskAPI.Process).Edit<t_Attachment>(Storage.Context1, o =>
                        {
                            o.Time = DateTime.Now;
                            o.Status = 2;
                        });
                    string path1 = Path.Combine(bs, (string.IsNullOrEmpty(PProcess) ? taskAPI.Process : PProcess));
                    files[0].SaveAs(path1 + @"\" + date + @"~" + fileName);
                    var att = new t_Attachment();
                    att.ID = date;
                    att.Process = (taskAPI.Process);
                    att.Incident = (string.IsNullOrEmpty(PProcess) ? taskAPI.Incident : PIncident);
                    att.Step = (string.IsNullOrEmpty(PProcess) ? taskAPI.Step : PStep);
                    att.UserName = UserAPI.UserName;
                    att.UserFullName = UserAPI.UserFullName;
                    att.Department = UserAPI.Department;
                    att.Time = DateTime.Now;
                    att.FileName = fileName;
                    att.FileClass = FileClass;
                    att.FilePath = path1 + @"\" + date + @"~" + fileName;
                    att.Status = 1;
                    Storage.Save(Storage.Context1, att);

                    res = "{ fileName:'" + fileName + "',userName:'" + att.UserFullName + "',id:'" + att.ID + "'}";
                }
                if (string.IsNullOrEmpty(res))
                {
                    res = "{error:'请选择文件！'}";
                }

                Response.Write(res);
                Response.End();
            }
            #endregion
            #region 保证金退款验证
            else if (AksRequest.GetQueryString("action") == "deposit" &&
                Path.GetFileName(Request.Files[0].FileName).Split('.')[0] == "保证金批量确认")
            {
                var files = Request.Files; //这里只能用<input type="file" />才能有效果,因为服务器控件是HttpInputFile类型
                var msg = string.Empty;
                var error = string.Empty;
                var res = "";
                var moreTwo = false;
                var bs = Util.AppSettings("path");
                var path = bs + @"\" + files[0].FileName;
                var stat = true;
                if (files.Count > 0)
                {
                    var depositTrans = new List<t_smd_DepositTran>();
                    string taskid = AksRequest.GetQueryString("taskid");
                    string PProcess = AksRequest.GetQueryString("PProcess");
                    string PStep = AksRequest.GetQueryString("PStep");
                    int PIncident = AksRequest.GetQueryInt("PIncident");
                    string FileClass = AksRequest.GetQueryString("FileClass");
                    var taskAPI = new TaskAPI(taskid);
                    var date = System.DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    var fileName = Path.GetFileName(files[0].FileName);
                    var iswrong = false;
                    var errorString = "<table class='formTable'>" +
                                                 "<tr>" +
                                                 "<td>序号</td><td>授权号</td><td>区域</td><td>省份</td><td>城市</td><td>城市类型</td><td>客户SAP账号</td><td>客户名称</td>" +
                                                 "<td>店面名称</td><td>渠道类型</td><td>设备安装时间</td><td>规定资产编号</td><td>发放前保证金余额</td><td>是否发放</td><td>发放情况</td><td>SAP</td><td>备注</td>" +
                                                 "</tr>";
                    string path1;
                    if (!string.IsNullOrEmpty(fileName))
                    {
                        var vdepostiBacth = (v_DepositBatchChange._AuthID != "").List<v_DepositBatchChange>();
                        var type = Path.GetExtension(fileName);
                        if (type == ".xls" || type == ".xlsx")
                        {
                            #region 保证金批量确认
                            if (fileName.Contains("保证金批量确认"))
                            {
                                IWorkbook hssfworkbook;
                                files[0].SaveAs(bs + @"\deposit" + type);
                                using (var fl = new FileStream(bs + @"\deposit" + type, FileMode.Open, FileAccess.ReadWrite)
                                    )
                                {
                                    hssfworkbook = WorkbookFactory.Create(fl);
                                }
                                var sheet = hssfworkbook.GetSheetAt(0);
                                var rows = sheet.GetRowEnumerator();



                                while (rows.MoveNext())
                                {
                                    bool isRong = false;
                                    var errorStr = "";
                                    var row = (IRow)rows.Current;
                                    var index = row.RowNum;
                                    if (index == 0)
                                    {
                                        continue;
                                    }
                                    var trans = new t_smd_DepositTran();

                                    var authid = Value(row.GetCell(0));
                                    var region = Value(row.GetCell(1));
                                    var province = Value(row.GetCell(2));
                                    var city = Value(row.GetCell(3));
                                    var cityclass = Value(row.GetCell(4));
                                    var dealerCode = Value(row.GetCell(5));
                                    var dealername = Value(row.GetCell(6));
                                    var storename = Value(row.GetCell(7));
                                    var channel = Value(row.GetCell(8));
                                    var deviceInstallDate = row.GetCell(9).DateCellValue.ToString("yyyy-MM-dd");
                                    var fullsetsn = Value(row.GetCell(10));
                                    var amount = Value(row.GetCell(11));
                                    var issue = Value(row.GetCell(19));
                                    var sap = Value(row.GetCell(20));
                                    var returnAmout = Value(row.GetCell(12));
                                    var needFF = Value(row.GetCell(14));

                                    var deposit =
                                        vdepostiBacth.FirstOrDefault(t => t.FullSetSN == fullsetsn);

                                    errorStr += "<tr><td>" + (index + 1) + "</td><td>" + authid + "</td><td><font>" +
                                                region + "</font></td>";
                                    errorStr += "<td><font>" + province + "</font></td>";
                                    errorStr += "<td><font>" + city + "</font></td>";
                                    errorStr += "<td><font>" + dealerCode + "</font></td>";
                                    errorStr += "<td><font>" + cityclass + "</font></td>";
                                    errorStr += "<td><font>" + dealername + "</font></td>";
                                    errorStr += "<td><font>" + storename + "</font></td>";
                                    errorStr += "<td><font>" + channel + "</font></td>";
                                    errorStr += "<td><font>" + deviceInstallDate + "</font><td>" + fullsetsn +
                                                "</td></td>";
                                    errorStr += "<td><font>" + amount + "</font></td>";

                                    var fontcolorblue = hssfworkbook.CreateFont();
                                    fontcolorblue.FontName = "微软雅黑";
                                    fontcolorblue.Color = HSSFColor.Red.Index;
                                    var cellStyle = hssfworkbook.CreateCellStyle();
                                    cellStyle.SetFont(fontcolorblue);

                                    if (Utils.StrToInt(issue, 0) > Utils.StrToInt(amount, 0))
                                    {
                                        isRong = true;
                                        errorStr += "<td><font>" + needFF + "</font></td><td><font style='color:red'>" +
                                                    issue +
                                                    "</font></td>";
                                        row.GetCell(19).CellStyle = cellStyle;
                                    }
                                    else if (Utils.StrToInt(issue, 0) == 0 && needFF.Trim() == "是" && sap == "")
                                    {
                                        isRong = true;
                                        errorStr += "<td><font style='color:red'>" + needFF +
                                                    "</font></td><td><font style='color:red'>请确认是否发放</font></td>";
                                        row.GetCell(19).CellStyle = cellStyle;
                                        row.GetCell(19).SetCellValue("请确认是否发放");
                                    }
                                    else if (Utils.StrToInt(issue, 0) == 0 && sap != "" && needFF.Trim() == "是")
                                    {
                                        isRong = true;
                                        errorStr += "<td><font>" + needFF +
                                                    "</font></td><td><font style='color:red'>请填写发放金额</font></td>";
                                        row.GetCell(19).CellStyle = cellStyle;
                                        row.GetCell(19).SetCellValue("请填写发放金额");
                                    }
                                    else
                                    {
                                        errorStr += "<td><font>" + needFF + "</font></td><td><font>" + issue +
                                                    "</font></td>";
                                    }
                                    if ((Utils.StrToInt(issue, 0) > 0 && sap == ""))
                                    {
                                        isRong = true;
                                        errorStr += "<td><font  style='color:red'>sap不能为空</font></td>";
                                        row.GetCell(20).CellStyle = cellStyle;
                                        row.GetCell(20).SetCellValue("sap不能为空");
                                    }
                                    else
                                    {
                                        errorStr += "<td><font>" + sap + "</font></td>";
                                    }

                                    if (isRong)
                                    {
                                        iswrong = true;
                                        errorString += errorStr + "<td></td></tr>";
                                    }

                                }

                                path1 = Path.Combine(bs, (string.IsNullOrEmpty(PProcess) ? taskAPI.Process : PProcess));
                                using (
                                    var fs = new FileStream(path1 + @"\" + date + @"~" + fileName, FileMode.OpenOrCreate,
                                        FileAccess.ReadWrite))
                                {
                                    hssfworkbook.Write(fs);
                                }


                            }

                            #endregion

                        }
                        else
                        {
                            res = "{error:'请上传exel格式的文件！'}";
                            Response.Write(res);
                            Response.End();
                        }
                    }

                    (t_Attachment.fileName == files[0].FileName
                        & t_Attachment.incident == TaskAPI.Incident
                        & t_Attachment.process == TaskAPI.Process).Edit<t_Attachment>(Storage.Context1, o =>
                        {
                            o.Time = System.DateTime.Now;
                            o.Status = 2;
                        });
                    path1 = Path.Combine(bs, (string.IsNullOrEmpty(PProcess) ? taskAPI.Process : PProcess));
                    if (!fileName.Contains("保证金批量确认"))
                    {
                        files[0].SaveAs(path1 + @"\" + date + @"~" + fileName);
                    }
                    var att = new H2.NET.Business.t_Attachment();
                    att.ID = date;
                    att.Process = (taskAPI.Process);
                    att.Incident = (string.IsNullOrEmpty(PProcess) ? taskAPI.Incident : PIncident);
                    att.Step = (string.IsNullOrEmpty(PProcess) ? taskAPI.Step : PStep);
                    att.UserName = UserAPI.UserName;
                    att.UserFullName = UserAPI.UserFullName;
                    att.Department = UserAPI.Department;
                    att.Time = System.DateTime.Now;
                    att.FileName = fileName;
                    att.FileClass = FileClass;
                    att.FilePath = path1 + @"\" + date + @"~" + fileName;
                    att.Status = 1;

                    Storage.Save(Storage.Context1, att);
                    if (iswrong)
                    {
                        errorString += "</table>";
                        res = "{error:'数据错误！',info:'" + errorString.Replace("'", "\"") + "',fileName:'" + fileName + "',userName:'" + att.UserFullName + "',id:'" + att.ID + "'}";
                        Response.Write(res);
                        Response.End();
                    }
                    else
                    {
                        res = "{ fileName:'" + fileName + "',userName:'" + att.UserFullName + "',id:'" + att.ID + "'}";
                    }

                }
                if (string.IsNullOrEmpty(res))
                {
                    res = "{error:'请选择文件！'}";
                }

                Response.Write(res);
                Response.End();
            }
            #endregion
            #region 上传附件

            else
            {
                HttpFileCollection files = Request.Files; //这里只能用<input type="file" />才能有效果,因为服务器控件是HttpInputFile类型
                string msg = string.Empty;
                string error = string.Empty;
                string res = "";
                bool moreTwo = false;
                if (files.Count > 0)
                {
                    string fileName = Path.GetFileName(files[0].FileName);
                    if (!string.IsNullOrEmpty(fileName))
                    {
                        string taskid = AksRequest.GetQueryString("taskid");
                        string PProcess = AksRequest.GetQueryString("PProcess");
                        string PStep = AksRequest.GetQueryString("PStep");
                        int PIncident = AksRequest.GetQueryInt("PIncident");
                        string FileClass = AksRequest.GetQueryString("FileClass");
                        var taskAPI = new TaskAPI(taskid);
                        string bs = Util.AppSettings("path");
                        string path = Path.Combine(bs, (string.IsNullOrEmpty(PProcess) ? taskAPI.Process : PProcess));
                        string date = System.DateTime.Now.ToString("yyyyMMddHHmmssfff");

                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        if (files[0].ContentLength > 10 * 1024 * 1024)
                        {
                            res = "{error:'附件大小必须在10MB以内，建议小于2MB！'}";
                            Response.Write(res);
                            Response.End();
                        }
                        if (files[0].ContentLength > 2 * 1024 * 1024)
                        {
                            moreTwo = true;
                        }

                        //文件保存
                        files[0].SaveAs(path + @"\" + date + @"~" + fileName);

                        //记录集保存
                        H2.NET.Business.t_Attachment att = new H2.NET.Business.t_Attachment();
                        att.ID = date;
                        att.Process = (taskAPI.Process);
                        att.Incident = (string.IsNullOrEmpty(PProcess) ? taskAPI.Incident : PIncident);
                        att.Step = (string.IsNullOrEmpty(PProcess) ? taskAPI.Step : PStep);
                        att.UserName = UserAPI.UserName;
                        att.UserFullName = UserAPI.UserFullName;
                        att.Department = UserAPI.Department;
                        att.Time = System.DateTime.Now;
                        att.FileName = fileName;
                        att.FileClass = FileClass;
                        att.FilePath = path + @"\" + date + @"~" + fileName;
                        att.Status = 1;
                        Storage.Save(Storage.Context1, att);
                        res = "{ fileName:'" + fileName + "',userName:'" + att.UserFullName + "',id:'" + att.ID + "'}";
                        if (moreTwo)
                        {
                            res = "{ fileName:'" + fileName + "',userName:'" + att.UserFullName + "',id:'" + att.ID +
                                  "',warn:'附件最好小于2MB'}";
                        }
                    }
                }
                if (string.IsNullOrEmpty(res))
                {
                    res = "{error:'请选择文件！'}";
                }
                Response.Write(res);
                Response.End();
            }

            #endregion
        }

        private static string Value(ICell row)
        {
            return row != null ? row.ToString() : "";
        }

    }
}